/*------------------------------------------------------
                hou_elearningGEN beta v1.0
Author: xtrung.net@gmail.com
Write On: 04/27/2008
Create On:4/13/2012 11:22:18 AM
------------------------------------------------------*/
using hou_elearning.Entity;
using hou_elearning.DataAccess;
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
namespace hou_elearning.Business
{
    public class TrangslideBRL
    {
        #region Init
        private static string EX_NOT_EXIST="Không Tồn Tại Trangslide Này";
		private static string EX_STIEUDE_EMPTY="Tiêu đề không được để trống";
		private static string EX_ID_INVALID="PK_iTrangslideID không hợp lệ";
        private static string EX_FK_ISLIDE_INVALID = "FK_iSlide không hợp lệ";

        #endregion
        #region Public Methods
        /// <summary>
        /// Get Trangslide Theo ID
        /// </summary>
        /// <param name="PK_iTrangslideID">Int64:Trangslide ID</param>
        /// <returns>TrangslideEntity</returns>        
        public static TrangslideEntity GetOne(Int64 PK_iTrangslideID)
        {
            
			if(PK_iTrangslideID<=0)
				throw new Exception(EX_ID_INVALID);
            return TrangslideDAL.GetOne(PK_iTrangslideID);
        }
        /// <summary>
        /// Get Trangslide Theo FK_ISlideID
        /// </summary>
        /// <param name="PK_iTrangslideID">Int64:Trangslide ID</param>
        /// <returns>TrangslideEntity</returns>        
        public static List<TrangslideEntity> GetByFK_iSlideID(Int64 FK_iSlideID)
        {

            if (FK_iSlideID <= 0)
                throw new Exception(EX_FK_ISLIDE_INVALID);
            return TrangslideDAL.GetByFK_iSlideID(FK_iSlideID);
        }
        /// <summary>
        /// Lấy về List các Trangslide
        /// </summary>
        /// <returns>List TrangslideEntity:List Trangslide Cần lấy</returns>
        public static List<TrangslideEntity> GetAll()
        {
            return TrangslideDAL.GetAll();
        }
        
        /// <summary>
        /// Kiểm tra và thêm mới Trangslide
        /// </summary>
        /// <param name="entity">Entity</param>
        /// <returns>Int64: ID của Trangslide Mới Thêm Vào</returns>
        public static Int64 Add(TrangslideEntity entity)
        {
            checkLogic(entity);
            checkDuplicate(entity, false);
            checkFK(entity);
            return TrangslideDAL.Add(entity);
        }
        /// <summary>
        /// Kiểm tra và chỉnh sửa Trangslide
        /// </summary>
        /// <param name="entity">TrangslideEntity</param>
        /// <returns>bool:kết quả thực hiện</returns>
        public static bool Edit(TrangslideEntity entity)
        {
            checkExist(entity.PK_iTrangslideID);
            checkLogic(entity);
            checkDuplicate(entity, true);
            checkFK(entity);
            return TrangslideDAL.Edit(entity);
        }
        /// <summary>
        /// Kiểm tra và xoá Trangslide
        /// </summary>
        /// <param name="PK_iTrangslideID">Int64 : PK_iTrangslideID</param>
        /// <returns>bool:kết quả thực hiện</returns>
        public static bool Remove(Int64 PK_iTrangslideID)
        {
            checkExist(PK_iTrangslideID);
            return TrangslideDAL.Remove(PK_iTrangslideID);
        }
        #endregion
        #region Private Methods
        private static void checkExist(Int64 PK_iTrangslideID)
        {
            TrangslideEntity oTrangslide=TrangslideDAL.GetOne(PK_iTrangslideID);
            if(oTrangslide==null)
                throw new Exception(EX_NOT_EXIST);
        }
        /// <summary>
        /// Kiểm tra logic Entity
        /// </summary>
        /// <param name="entity">TrangslideEntity: entity</param>
        private static void checkLogic(TrangslideEntity entity)
        {   
			if (String.IsNullOrEmpty(entity.sTieude))
				throw new Exception(EX_STIEUDE_EMPTY);
        }
        /// <summary>
        /// Kiểm tra trùng lặp bản ghi
        /// </summary>
        /// <param name="entity">TrangslideEntity: TrangslideEntity</param>
        private static void checkDuplicate(TrangslideEntity entity,bool checkPK)
        {
            /* 
            Example
            List<TrangslideEntity> list = TrangslideDAL.GetAll();
            if (list.Exists(
                delegate(TrangslideEntity oldEntity)
                {
                    bool result =oldEntity.FIELD.Equals(entity.FIELD, StringComparison.OrdinalIgnoreCase);
                    if(checkPK)
                        result=result && oldEntity.PK_iTrangslideID != entity.PK_iTrangslideID;
                    return result;
                }
            ))
            {
                list.Clear();
                throw new Exception(EX_FIELD_EXISTED);
            }
            */
        }
        /// <summary>
        /// Kiểm tra tồn tại khóa ngoại
        /// </summary>
        /// <param name="entity">TrangslideEntity:entity</param>
        private static void checkFK(TrangslideEntity entity)
        {
            
        }
        #endregion
    }
}
